
<html>
<head>
    <meta content="text/html; charset=utf-8" http-equiv="content-type">
    <title>
        js 调用 ets
    </title>
    <style>
        * {
            font-size : 30px;
            }
        #test {
            position: absolute;
            left: 0;
            right: 0;
            top: 100px;
            margin: auto;
            height: 500px;
            width: 500px;
        }
        .p1 {
            height: 3rem;
            width: 100%;
        }
    </style>
</head>
<script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.9.0/vconsole.min.js"></script>
<body>
<div id="test">
    <p>
        <input class="p1" type="text" value="用户姓名"/>
        <div id="text1"></div>
    </p>
    <p>
        <input class="p1" type="text" value="用户年龄"/>
        <div id="text2"></div>
    </p>·
    <p>
        <input  class="p1" type="button" id="enter" value="发消息给Native" onclick="testClick()"/>
    </p>
</div>
</body>
<script>
    var vConsole = new window.VConsole();
     window.bridge.callNative = function(str) {}
     window.bridge.callNativeToJs = function(str) {
         // 原生回调
         console.info(str)
         let o = JSON.parse(str)
         document.getElementById('text1').innerHTML = o.name
         document.getElementById('text2').innerHTML = o.age
     }

     function testClick() {
        // 调用原生 getUserInfo
        let req = {"function": "getUserInfo"}
        bridge.callNative(JSON.stringify(req))
     }
</script>
</html>